<?php
    $x = new Zend_Auth_Storage_Session('User_Auth');
    $y = $x->read();
    $logged_in_user_id = "0";
    if (!empty($y))
        $logged_in_user_id = $x->read()->user_id;
    $setAppPlugin = new Application_Plugin_SetApp();
//    prd($y);
    $user_image = getUserImage($this->user['user_id']);
    $user_id = $this->user['user_id'];


    $model = new Application_Model_Common();
    $custom_model = new Application_Model_Custom();
    $user_rating = $custom_model->getEventAverageRating($user_id);

    $user_gender = $this->user["user_gender"];

    if ($user_gender == "f")
        $user_gender = "Female";
    else
        $user_gender = "Male";
?>
<div class="alert-message show-profile" id="show-profile-<?php echo $this->user['user_id']; ?>">
    <div class="am-wrapper">
        <a href="#close" class="close-button"></a>
        <div class="title">
            <?php echo $this->user['user_first_name']; ?> <strong><?php echo $this->user['user_last_name']; ?></strong>
        </div>
        <div class="ginfos">
            <div class="fr">
                <img src="<?php echo $user_image; ?>" alt="<?php echo $this->user['user_first_name'] . " " . $this->user['user_last_name']; ?>" />
            </div>
            <div class="fr sum">
                <p>Education: <span class="v"><?php echo!empty($this->user['user_education']) ? $this->user['user_education'] : 'NA'; ?></span></p>
                <p>Work: <span class="v"><?php echo $this->user['user_work']; ?></span></p>
                <!--<p>Experience: <span class="v">12 years</span></p>-->
                <?php
                    if (!empty($y))
                    {
                        ?>
                        <div class="add-friends">
                            <?php
                            if ($this->isLoggedIn == 'yes' && $this->user['user_id'] != $y->user_id):
                                ?>
                                <a href="javascript:;" class="rbox select bluebutton2 fr">
                                    <?php
                                    $add_to_another_group = 'yes';
                                    //echo $this->user['user_id'];
                                    //if (!in_array($this->user['user_id'], $this->frndArr))
                                    {
                                        ?>
                                        <span class = "txt">Add as Friend</span><span class = "arrow"></span>
                                        <?php
                                    }
                                    ?>    
                                    <ul class="dropdown">
                                        <?php
                                        foreach ($this->friendGroupsAndFriends as $gKey => $gValue)
                                        {
                                            if ($add_to_another_group == 'yes' && (in_array_custom($this->user['user_id'], $gValue['friends_records'], 'user_id') ))
                                                continue;
                                            ?>    
                                            <li class="first" onclick="addFriend('<?php echo getEncryptedString($this->user['user_id']); ?>', '<?php echo $gValue['group_id']; ?>', this);"><?php echo $gValue['group_name']; ?> <span>(<?php echo count($gValue['friends_records']); ?>)</span></li>
                                            <?php
                                        }
                                        ?>
                                        <li class="n">

                                        </li>
                                        <li class="n">

                                        </li>
                                        <?php
//                                if ($add_to_another_group != 'yes')
//                                {
                                        ?>
                                        <li class="c">
                                            Create Group
                                        </li>
                                        <?php
//                                }
                                        ?>    
                                    </ul>
                                </a>
                                <?php
                            endif;
                            ?>
                        </div>
                        <?php
                    }
                ?>
            </div>
            <div class="cf"></div>
        </div>
        <ul class="tabs tab-menu">
            <li class="active"><a href="#personal-info-<?php
                    echo $this->user['user_id'];
                    echo!empty($this->pmessage) ? $this->pmessage : '';
                    echo isset($this->key) ? $this->key : '';
                ?>">Personal info</a></li>
            <li><a href="#rate-comment-<?php
                    echo $this->user['user_id'];
                    echo!empty($this->pmessage) ? $this->pmessage : '';
                    echo isset($this->key) ? $this->key : '';
                ?>">Rates & comments</a></li>
            <li><a href="#cevent-tab-<?php
                    echo $this->user['user_id'];
                    echo!empty($this->pmessage) ? $this->pmessage : '';
                    echo isset($this->key) ? $this->key : '';
                ?>">Created events</a></li>
                <?php
                    if (!empty($y))
                    {
                        if ($this->user['user_id'] != $logged_in_user_id)
                        {
                            echo '<li class="send-im"><a href="#im-tab-' . $this->user['user_id'] . (!empty($this->pmessage) ? $this->pmessage : '') . (isset($this->key) ? $this->key : '') . '">IM</a></li>';
                        }
                    }
                ?>
        </ul>
        <div class="cf"></div>
        <div class="tabs-content">
            <div class="tcontent personal-info active" id="personal-info-<?php
                echo $this->user['user_id'];
                echo!empty($this->pmessage) ? $this->pmessage : '';
                echo isset($this->key) ? $this->key : '';
            ?>">
                <div class="pileft fl">
                    <p>Username: <strong><?php echo $this->user['user_username']; ?></strong></p>
                    <p>Date of birth: <strong><?php echo date("d F Y", strtotime($this->user['user_dob'])); ?></strong></p>
                    <p>From: <strong><?php echo $this->user['user_location']; ?></strong></p>
                    <p>Gender: <strong><?php echo $user_gender; ?></strong></p>
                    <p><br /></p>
                    <p>Published Events: <strong class="blu"><?php echo @$this->getUserEventsCounts["published"]; ?></strong></p>
                    <p>Private: <strong class="blu"><?php echo @$this->getUserEventsCounts["private"]; ?></strong></p>
                    <p>Public: <strong class="blu"><?php echo $this->getUserEventsCounts["public"]; ?></strong></p>
                    <p><br /></p>
                    <p>Attended Events: <strong class="org"><?php echo @$this->getUserEventsCounts["attended"]; ?></strong></p>
                </div>
                <div class="pi-right fr">
                    <p>Overall <strong>Rating</strong></p>
                    <!--<span class="rate-star fr" rel="9"></span>-->
                    <?php
                        if (empty($user_rating))
                            $user_rating = "0";
                        $yellow_star_count = $user_rating;
                        $grey_start_count = RATING_STARS_MAX - $user_rating;
                    ?>
                    <ul class="profile-stars">
                        <?php
                            for ($yellow_i = $yellow_star_count; $yellow_i >= "1"; $yellow_i--)
                            {
                                echo '<li><img src="' . IMAGES_PATH . '/star-yellow.png" alt="stars"/></li>';
                            }
                            for ($grey_i = "1"; $grey_i <= $grey_start_count; $grey_i++)
                            {
                                echo '<li><img src="' . IMAGES_PATH . '/star-grey.png" alt="stars"/></li>';
                            }
                        ?>
                    </ul>
                    <div class="cf"></div>
                    <p class="note ralign"><?php echo $user_rating . "/" . RATING_STARS_MAX; ?> Average rating</p>
                    <p><br /></p>
                    <p><a href="<?php echo getFacebookUsernameUrl($this->user['facebook_username']); ?>" target="_blank" class="blu social-icon f"><?php echo $this->user['facebook_username']; ?></a></p>
                    <p><a href="<?php echo getTwitterUsernameUrl($this->user['twitter_username']); ?>" target="_blank" class="blu social-icon t"><?php echo $this->user['twitter_username']; ?></a></p>
                    <p><a href="<?php echo getLinkedinUsernameUrl($this->user['linkedin_username']); ?>" target="_blank" class="blu social-icon l"><?php echo $this->user['linkedin_username']; ?></a></p>
                </div>
                <div class="cf"></div>
                <p><br /></p>
                <div class="line-ob"><span>About <strong>Me</strong></span></div>
                <p class="v">Info:</p>
                <p><br /></p>
                <p class="fi"><?php echo $this->user['user_bio']; ?></p>

                <div class="line"></div>
                <?php
                    if (!empty($y))
                    {
                        ?>
                        <div>
                            <a href="#" class="rbox sfebutton inv-button select">
                                <span class="txt"><strong>Invite me</strong><br /><span>to your event</span></span>
                                <span class="arrow"></span>
                                <ul class="dropdown">
                                    <?php
                                    if ($this->myEvents && !empty($this->myEvents))
                                    {

                                        $event_count = count($this->myEvents);
                                        $i = "1";

                                        foreach ($this->myEvents as $me_key => $me_value)
                                        {
                                            $event_id = $me_value["event_id"];
//                                                pr($event_id);
                                            $enc_event_id = getEncryptedString($event_id);
                                            $event_images = getEventImages($event_id);
                                            $event_title = $me_value["event_title"];
                                            $event_info = stripslashes($me_value["event_info"]);

                                            $class_name = "";
                                            if ($i == $event_count)
                                            {
                                                $class_name = "last";
                                            }

//                                            if (!$setAppPlugin->checkIfEventAccepted($this->user['user_id'], $event_id))
//                                            {
                                            ?>
                                            <li class="<?php echo $class_name; ?>">
                                                <img src="<?php echo $event_images[0]; ?>" alt="<?php echo $event_title; ?>" class="fl" />
                                                <div class="details fl">
                                                    <div><p><?php echo $event_info; ?></p></div>
                                                </div>
                                                <div class="fl chk inviteToEvent">
                                                    <!--<input type="checkbox" />-->
                                                    <?php
                                                    $ifEventJoined = $setAppPlugin->checkIfEventJoined($this->user['user_id'], $event_id);
                                                    if ($ifEventJoined)
                                                    {
                                                        $shareClassName = "uncheck";
                                                        $shareText = "Shared";
                                                    }
                                                    else
                                                    {
                                                        $shareClassName = "bookmark";
                                                        $shareText = "Share event";
                                                    }
                                                    ?>
                                                    <button class="<?php echo $shareClassName; ?>" rel="<?php echo $enc_event_id; ?>" id="<?php echo $this->user['user_id']; ?>"><?php echo $shareText; ?></button>
                                                </div>
                                                <div class="cf"></div>
                                            </li>
                                            <?php
                                            $i++;
//                                            }
                                        }
                                    }
                                    else
                                    {
                                        echo '<li class="last">No created events to display</li>';
                                    }
                                    ?>
                                </ul>
                            </a>
                        </div>
                        <?php
                    }
                ?>
            </div>
            <div class="tcontent rate-comment" id="rate-comment-<?php
                echo $this->user['user_id'];
                echo!empty($this->pmessage) ? $this->pmessage : '';
                echo isset($this->key) ? $this->key : '';
            ?>">
                <div class="fl">
                    <p>Overall <strong>Rating</strong></p>
                    <!--<span class="rate-star fl" rel="9"></span>-->
                    <?php
                        $yellow_star_count = $user_rating;
                        $grey_start_count = RATING_STARS_MAX - $user_rating;
                    ?>
                    <ul class="profile-stars">
                        <?php
                            for ($yellow_i = $yellow_star_count; $yellow_i >= "1"; $yellow_i--)
                            {
                                echo '<li><img src="' . IMAGES_PATH . '/star-yellow.png" alt="stars"/></li>';
                            }
                            for ($grey_i = "1"; $grey_i <= $grey_start_count; $grey_i++)
                            {
                                echo '<li><img src="' . IMAGES_PATH . '/star-grey.png" alt="stars"/></li>';
                            }
                        ?>
                    </ul>
                    <div class="cf"></div>
                    <p class="note"><?php echo $user_rating . "/" . RATING_STARS_MAX; ?> Average rating</p>
                </div>
                <div class="cf"></div>
                <div class="line"></div>
                <div class="comments-list-<?php echo $this->user['user_id']; ?>">
                    <?php
                        $model = new Application_Model_Common;
                        $custom_model = new Application_Model_Custom();
                        $otherUserCommentsArray = $custom_model->getMyReviewsList($user_id);
//                        prd($otherUserCommentsArray);

                        if (!empty($otherUserCommentsArray))
                        {
                            foreach ($otherUserCommentsArray as $o_key => $o_value)
                            {
                                $friend_id = $o_value["user_id"];
                                $friend_image = getUserImage($friend_id);
                                $friend_full_name = $o_value["user_first_name"] . " " . $o_value["user_last_name"];
                                $event_title = $o_value["event_title"];
                                $comment = $o_value["ecm_comment"];
                                $posted_on = date("d F Y", strtotime($o_value["ecm_timestamp"]));
                                $stars_rated = $o_value["ecm_ratings"];
                                $event_link = $this->baseUrl("eventdetail/" . getEncryptedString($o_value["ecvm_event_id"]));
                                ?>
                                <div class="comm">
                                    <div class="avt fl">
                                        <img src="<?php echo $friend_image; ?>" alt="<?php echo $friend_full_name; ?>" />
                                    </div>
                                    <div class="details fl">
                                            <div class="fl dl" style="width: 100%;">
                                                <p class="fl" style="max-width: 178px;">
                                                <!--<span class="title"><a href="#"><?php echo $friend_full_name; ?></a></span>--> 
                                                <span class="title"><?php echo $friend_full_name; ?></span> 
                                                <a href="<?php echo $event_link; ?>" class="tlink blu"><?php echo $event_title; ?></a>
                                            </p>
                                            

                                            <ul class="profile-stars" style="float: right;">
                                                <?php
                                                for ($yellow_i = $yellow_star_count; $yellow_i >= "1"; $yellow_i--)
                                                {
                                                    echo '<li><img src="' . IMAGES_PATH . '/star-yellow.png" alt="stars"/></li>';
                                                }
                                                for ($grey_i = "1"; $grey_i <= $grey_start_count; $grey_i++)
                                                {
                                                    echo '<li><img src="' . IMAGES_PATH . '/star-grey.png" alt="stars"/></li>';
                                                }
                                                ?>
                                            </ul>
                                            <div class="cf"></div>
                                            <p class="txt"><?php echo $comment; ?></p>
                                            <p class="time">Posted on <span class="blu"><?php echo $posted_on; ?></span></p>
                                        </div>
                                    </div>
                                    <div class="cf"></div>
                                </div>
                                <?php
                            }
                        }
                        else
                        {
                            echo '<h3>No ratings yet</h3>';
                        }
                    ?>
                </div>
            </div>
            <div class="tcontent cevent-tab" id="cevent-tab-<?php
                echo $this->user['user_id'];
                echo!empty($this->pmessage) ? $this->pmessage : '';
                echo isset($this->key) ? $this->key : '';
            ?>">
                <div class="events-list">
                    <?php
                        //prd($this->friend_created_events);
                        if (!empty($this->friend_created_events))
                        {
                            foreach ($this->friend_created_events as $fr_key => $fr_value)
                            {
                                if (!empty($fr_value) && !empty($fr_value["event_id"]))
                                {
                                    $event_id = $fr_value["event_id"];
                                    $event_title = $fr_value["event_title"];
                                    $title_length = strlen($event_title);
                                    if ($title_length > 30)
                                    {
                                        $event_title = substr($event_title, 0, 30) . "...";
                                    }
//                              $event_time = date("H:m", strtotime($fr_value["event_time"])) . " " . TIME_ZONE;
                                    $event_time = date("g:i a", strtotime($fr_value["event_time"]));
                                    $event_type = ucwords($fr_value["event_type"]);
                                    $event_group_size = $fr_value["event_group_size"];
                                    if (empty($event_group_size))
                                        $event_group_size = "NA";

//                                $event_date_array = json_decode($fr_value["event_date"]);
//                                $event_date = $event_date_array->day[0] . " " . date("F", strtotime($event_date_array->month[0])) . " " . $event_date_array->year[0];

                                    $event_date = getEventDate($fr_value["event_date"]);

                                    $event_address = stripslashes(trim($fr_value["event_address"] . ", " . $fr_value["event_location"]));
                                    $event_info = trim($fr_value["event_info"]);

                                    $category_id = $fr_value["category_id"];
                                    $category_name = $fr_value["category_name"];
                                    $subcategory_id = $fr_value["subcategory_id"];
                                    $subcategory_name = $fr_value["subcategory_name"];
                                    $creator_full_name = $fr_value["user_first_name"] . " " . $fr_value["user_last_name"];
                                    if ($creator_full_name == " ")
                                        $creator_full_name = "NA";

                                    $first_post_class = "";
                                    if ($all_event_i == "1")
                                        $first_post_class = " first";

                                    $event_images = getEventImages($event_id);
                                    $event_link = $this->baseUrl("eventdetail/" . getEncryptedString($event_id));
                                    ?>
                                    <div class="event">
                                        <div class="ewrap">
                                            <div class="pimg fl">
                                                <img src="<?php echo $event_images[0]; ?>" alt="<?php echo $event_title; ?>">
                                            </div>
                                            <div class="details fl">
                                                <div class="e-title">
                                                    <a class="p-name tlink" href="<?php echo $event_link; ?>"><?php echo $event_title; ?></a>
                                                    <span class="p-cates">
                                                        <span>in </span><a class="org tlink" href="<?php echo $this->baseUrl("event/search?cat_search=$category_id"); ?>"><?php echo $category_name; ?></a> / <a class="org tlink" href="<?php echo $this->baseUrl("event/search?subcat_search=$subcategory_id"); ?>"><?php echo $subcategory_name; ?></a>
                                                    </span>
                                                    <span class="p-time"><?php echo $event_date . " / " . $event_time; ?></span>
                                                </div>
                                                <div class="infos">
                                                    <span class="group">Group size</span><span><?php echo $event_group_size; ?></span>
                                                    <span>/</span><span class="org">Address</span><span><?php echo $event_address; ?></span>
                                                    <span class="publish fr blu"><a href="#"><?php echo $event_type; ?></a></span>
                                                    <div class="cf"></div>
                                                    <div class="desc fl">
                                                        <?php echo $event_info; ?>
                                                    </div>
                                                    <div class="fr view">
                                                        <a class="rbox bluebutton2" href="<?php echo $event_link; ?>"><strong>View</strong></a>
                                                    </div>
                                                    <div class="cf"></div>
                                                </div>
                                            </div>
                                            <div class="cf"></div>
                                        </div>
                                    </div>
                                    <?php
                                }
                                else
                                {
                                    echo '<h3>No created events<h3>';
                                    break;
                                }
                            }
                        }
                        else
                        {
                            echo '<h3>No created events<h3>';
                        }
                    ?>
                </div>
            </div>
            <?php
                if (!empty($y))
                {
                    ?>
                    <div class="tcontent im-tab" id="im-tab-<?php
                    echo $this->user['user_id'] . (!empty($this->pmessage) ? $this->pmessage : '') .
                    (isset($this->key) ? $this->key : '');
                    ?>">
                        <h1 class="im-title">Your <span class="blu">IM</span></h1>
                        <form id="im-form" method="post" name="profileComment" id="profileComment" onsubmit="return validateForm('reply', this)" >
                            <p><textarea maxlength="1000" name="commbox" class="radius area commbox" onfocus="this.style.borderColor = '#1996d4'" onblur="this.style.borderColor = '#cfcfcf'" style="border-color: rgb(207, 207, 207);"></textarea></p>
                            <p class="note">1000 characters max</p>
                            <p><br /></p>
                            <div class="fl">
                                <!--<a href="#" class="bluefbutton fl"><strong>Send IM</strong></a>-->
                                <input type="hidden" class="message_to"  value="<?php echo $this->user['user_id']; ?>" name="message_to">
                                <input type="submit" class="bluefbutton fl" name="sbmt" value="Send IM"/>
                            </div>
                        </form>
                        <div class="fr pass-message"><a href="<?php echo $this->baseUrl("message"); ?>" class="org tlink">View Past messages with <?php echo $this->user['user_first_name'] . " " . $this->user['user_last_name']; ?></a></div>
                        <div class="cf"></div>
                    </div>
                    <?php
                }
            ?>
        </div>
    </div>
</div>
